'use strict';

//获取评论接口
module.exports = app => {
    return class CommentListService extends app.Service {
        constructor(ctx) {
            super(ctx);
        }

        /**
         * 咨询评论分页
         * @param params
         */
        async getCommentList(params) {

            let url = this.app.urls('comment');
            const result = await this.ctx.fetch(url, {
                method: 'get',
                dataType: 'json',
                data:{
                    objectId: params.objectId,
                    objectType: 4,
                    pageNo:params.pageNo,
                },
            });
            this.app.logger.info(result.data);
            let data = result.data;

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data.data;
        }


        /**
         *帖子评论分页
         * @param params
         */
        async getPostCommentList(params) {

            let url = this.app.urls('getpostcomment');
            const result = await this.ctx.fetch(url, {
                method: 'get',
                dataType: 'json',
                data:{
                    forumPostId:params.id,
                    pageNo:params.pageNo,
                },
            });
            this.app.logger.info(result.data);
            let data = result.data;

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data.data;
        }


    }

};
